package com.Lgwd.service.backService.backServiceImpl;

import com.Lgwd.dao.BackDao;
import com.Lgwd.entity.ItemPropertyEntity;
import com.Lgwd.entity.UserItemInfoEntity;
import com.Lgwd.repository.UserItemInfoRepository;
import com.Lgwd.service.backService.UserItemInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserItemInfoServiceImpl implements UserItemInfoService {
    @Autowired
    UserItemInfoRepository userItemInfoRepository;

    /**
     * 获取到的装备属性 保存记录
     * @param itemPropertyEntity
     * @param user_account
     */
    @Override
    public void addItemToBack(ItemPropertyEntity itemPropertyEntity,String user_account,Integer integer,String item_id,Integer item_code_id) {
        UserItemInfoEntity userItemInfoEntity=new UserItemInfoEntity();
        userItemInfoEntity.setItem_id(item_id);
        userItemInfoEntity.setFlag(1);
        userItemInfoEntity.setUser_account(user_account);
        userItemInfoEntity.setProperty_quality(integer);
        userItemInfoEntity.setItem_profession(itemPropertyEntity.getItem_profession());
        userItemInfoEntity.setItem_code_id(item_code_id);
        BeanUtils.copyProperties(itemPropertyEntity,userItemInfoEntity);
        userItemInfoRepository.save(userItemInfoEntity);
    }

    /**
     * 查看某一个物品的详细属性
     * 根据  item_id 查询useriteminfo表装备的详细属性
     * item_id由前端传入
     */
    @Override
    public UserItemInfoEntity findItemInfoByItemId(BackDao backDao) {
        return userItemInfoRepository.findBackInfoEntityById(backDao.getItem_id());
    }

    @Override
    public UserItemInfoEntity findItemInfoByItemIdString(String itemId) {
        return userItemInfoRepository.findBackInfoEntityById(itemId);
    }
}
